#! /bin/sh
#
#   Examples build helper
#   Syntax: build all | clean
#
ZMQOPTS='-lzmq -std=c++11'
if pkg-config libzmq --exists; then
    ZMQOPTS="$(pkg-config libzmq --cflags --libs) -std=c++11"
fi
if [ /$1/ = /all/ ]; then
    echo "Building C++ examples..."
    for MAIN in `egrep -l "main \(" *.cpp`; do
        echo "$MAIN"
        ./c -p -l $ZMQOPTS -q $MAIN
    done
elif [ /$1/ = /clean/ ]; then
    echo "Cleaning C++ examples directory..."
    rm -f *.opp *.lst core
    for MAIN in `egrep -l "main \(" *.cpp`; do
        rm -f `basename $MAIN .cpp`
    done
elif [ -f $1.cpp ]; then
    echo "$1"
    ./c -p -l $ZMQOPTS -q $1
else
    echo "syntax: build all | clean"
fi

